package cn.net.ecode.elec.api.web;

import cn.net.ecode.annotation.Login;
import cn.net.ecode.common.utils.CacheUtils;
import cn.net.ecode.common.utils.StringUtils;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.constant.SendSmsTypeEnum;
import cn.net.ecode.mdm.entity.MdmBtypeInfo;
import cn.net.ecode.mdm.service.MdmBtypeInfoService;
import cn.net.ecode.modules.sys.entity.Dict;
import cn.net.ecode.modules.sys.utils.DictUtils;
import cn.net.ecode.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AppUserController
 * @Description 用户注册接口
 * @Author AlanShelby
 * @Date 2019/8/27 0027 8:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/btype")
public class AppBtypeController extends BaseController {
    @Autowired
    MdmBtypeInfoService mdmBtypeInfoService;

    /**
     * 获取企业数据
     *
     * @param btypeId
     * @return
     */
    @Login
    @RequestMapping(value = "btypeInfo", method = RequestMethod.GET)
    public R userInfo(@RequestParam String btypeId) {
        MdmBtypeInfo mdmBtypeInfo = new MdmBtypeInfo();
        mdmBtypeInfo.setId(btypeId);
        mdmBtypeInfo = mdmBtypeInfoService.get(mdmBtypeInfo);
        return R.ok().put("mdmBtypeInfo", mdmBtypeInfo);
    }

    /**
     * @Method btypeDictList
     * @Description 获取企业字典数据
     * @Author AlanShelby
     * @Date 20:11 2019/9/5 0005
     * @Param []
     * @Return cn.net.ecode.util.R
     */
    @RequestMapping(value = "btypeDictList", method = RequestMethod.GET)
    public R btypeDictList() {
        List<Dict> btypeClassify = DictUtils.getDictList("btype_classify");
        List<Dict> btypeArea = DictUtils.getDictList("btype_area");
        List<Dict> btypeType = DictUtils.getDictList("btype_type");
        List<Dict> btypeScale = DictUtils.getDictList("btype_scale");
        List<Dict> voltageClassCode = DictUtils.getDictList("voltageClassCode");

        return R.ok().put("btypeClassify", btypeClassify)
                .put("btypeArea", btypeArea)
                .put("btypeScale", btypeScale)
                .put("btypeType", btypeType)
                .put("voltageClassCode", voltageClassCode);
    }

    /**
     * @Method editBtypeInfo
     * @Description 编辑企业信息
     * @Author AlanShelby
     * @Date 8:53 2019/9/9 0009
     * @Param [mdmBtypeInfo]
     * @Return cn.net.ecode.util.R
     */
    @RequestMapping(value = "/editBtypeInfo", method = RequestMethod.POST)
    public R editBtypeInfo(@RequestBody MdmBtypeInfo mdmBtypeInfo) {
        StringBuilder message = new StringBuilder();
        if (!beanValidator(message, mdmBtypeInfo)) {
            return R.error(message.toString());
        }

        mdmBtypeInfo.setIsNewRecord(false);
        mdmBtypeInfoService.update(mdmBtypeInfo);

        return R.ok();
    }
}
